package com.itheima.dao;

import com.itheima.common.entity.SetmealCountVO;
import com.itheima.common.entity.SetmealCountVO2;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDao {
    /**
     * 插入套餐
     * @param
     */
    void insert(Setmeal setmeal);
    /**
     * 编辑套餐
     * @param
     */
    void update(Setmeal setmeal);

    @Select("select * from t_setmeal where id=#{id};")
    Setmeal findById(Integer id);

    /**
     * 模糊查询
     * @param queryString
     * @return
     */
    List<Setmeal> findByString(String queryString);

    /**
     * 获取套餐名称 与 套餐被预约数
     * @return
     */
    @Select("select  name, count(*) as value from t_order left join t_setmeal ts\n" +
            "    on t_order.setmeal_id = ts.id   group by setmeal_id order by value DESC;")
    List<SetmealCountVO> getNameCount();

    @Select("select  name, count(*) as value,remark from t_order left join t_setmeal ts " +
            "    on t_order.setmeal_id = ts.id   group by setmeal_id order by value DESC;")
    List<SetmealCountVO2> getNameCount2();

    @Select("select * from t_setmeal")
    List<Setmeal> findAll();

    Setmeal findById4Detail(Integer id);
}
